import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const router = new Router({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      name: 'Home',
      component: () => import('@/views/Home'),
      hidden: true,
      redirect: '/Map',//首页
      children:[
        /* 
          Gis地图
        */
        {path: '/Map', name: 'Map', component: ()=>import('@/views/GisMap/Map/Map.vue')},
        {path: '/Cesium1', name: 'Cesium1', component: ()=>import('@/views/Cesium/Cesium1.vue')},
        {path: '/d3index1', name: 'd3index1', component: ()=>import('@/views/D3/d3index1.vue')},
        {path: '/d3index2', name: 'd3index2', component: ()=>import('@/views/D3/d3index2.vue')},
        {path: '/d3index3', name: 'd3index3', component: ()=>import('@/views/D3/d3index3.vue')},
        {path: '/d3index4', name: 'd3index4', component: ()=>import('@/views/D3/d3index4.vue')},

       
      ]
    }
  ]
})


router.beforeEach((to,from,next)=>{
  const blackSpace = ['UserList']
  const token = window.localStorage.getItem('token')
  if(blackSpace.includes(to.name)){
    if(token){
      next()
    }else{
      next()
    }
  }else{
    next()
  }
  // console.log(window.localStorage.getItem('token'),to,from,blackSpace)
  // console.log(!!(blackSpace.includes(to.name) && token))
  // if(!!(blackSpace.includes(to.name) && token)) next()
  // else next({name:'login'})
})
export default router